package com.bringspring.system.message.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bringspring.system.permission.entity.OrganizeEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 开发平台组
 * @version V1.0.0
 * @copyright 股份有限公司
 * @date 2022/11/22 10:16
 */
public class JsonObjectUtilPer {


    /**
     * json转化为组织的实体对象.
     *
     * @param json json数据
     * @param t    实体对象
     */
    public static List<OrganizeEntity> jsonToOrganEntity(JSONObject json) {
        String jsonObjString = json .getString("department");
        HashMap<String, String> data = new HashMap<String, String>();
//        Iterator it = json.keys();
//        while(it.hasNext()){
//            String key = String.valueOf(it.next().toString());
//            String value = (String)json.get(key).toString();
//            data.put(key, value);
//        }
        Map<String, Object> userMap = new HashMap<>();
        //循环转换
        for (Map.Entry<String, Object> entry : json.entrySet()) {
            userMap.put(entry.getKey(), entry.getValue());
        }
        List departmentQy = (List) JSONArray.parseArray(jsonObjString, List.class);

        return null;
    }
    public static Map getValue(String param) {
        Map map = new HashMap();
        String str = "";
        String key = "";
        Object value = "";
        char[] charList = param.toCharArray();
        boolean valueBegin = false;
        for (int i = 0; i < charList.length; i++) {
            char c = charList[i];
            if (c == '{') {
                if (valueBegin == true) {
                    value = getValue(param.substring(i, param.length()));
                    i = param.indexOf('}', i) + 1;
                    map.put(key, value);
                }
            } else if (c == '=') {
                valueBegin = true;
                key = str;
                str = "";
            } else if (c == ',') {
                valueBegin = false;
                value = str;
                str = "";
                map.put(key, value);
            } else if (c == '}') {
                if (str != "") {
                    value = str;
                }
                map.put(key, value);
                return map;
            } else if (c != ' ') {
                str += c;
            }
        }
        return map;
    }
}
